package com.sense.kukoo.biz_me.adapter

import com.sense.kukoo.biz_me.adapter.provider.MeChannelContentEmptyItemProvider
import com.sense.kukoo.biz_me.adapter.provider.MeChannelContentHintItemProvider
import com.sense.kukoo.biz_me.adapter.provider.MeChannelContentNormalItemProvider
import com.sense.kukoo.biz_me.adapter.provider.MeChannelTitleItemProvider
import com.sense.kukoo.common.media.bean.LocalMediaListItemBean
import com.sense.kukoo.common.media.watcher.UserWatcher
import com.sense.kukoo.common.repo.biz.ChannelContentBean
import com.sense.kukoo.common.repo.http.bean.IndexContentBean
import com.sense.kukoo.common.repo.http.bean.UserInfoBean
import com.sense.kukoo.common.wiget.adapter.MultiItemAdapter

class MeChannelAdapter(

    val data:List<ChannelContentBean>,
    val listener: IndexContentEventListener,

): MultiItemAdapter<ChannelContentBean>(data) {

    var mCurrentMusic: LocalMediaListItemBean? = null
    var mCurrentPlayState: Int = UserWatcher.MusicStateWatcher.STATE_NOT_PLAYING

    private val mMeChannelContentNormalItemProvider = MeChannelContentNormalItemProvider(listener)
    private val mMeChannelContentHintItemProvider = MeChannelContentHintItemProvider(listener)

    init {
        addItemProvider(MeChannelTitleItemProvider(listener))
        addItemProvider(mMeChannelContentNormalItemProvider)
        addItemProvider(mMeChannelContentHintItemProvider)
        addItemProvider(MeChannelContentEmptyItemProvider())
    }

    override fun getItemType(data: MutableList<ChannelContentBean>, position: Int): Int {
        return data.get(position).type
    }

    interface IndexContentEventListener{
        fun onUserIconClick(user: UserInfoBean)
        fun onUserChannelClick(user: UserInfoBean)
        fun onUserIdClick(user: UserInfoBean)
        fun onItemClick(data: IndexContentBean)
        fun onChannelClick(data: IndexContentBean)
        fun onBtnPlayClick(data: IndexContentBean)
        fun onBtnFollowersClick(user: UserInfoBean)
        fun onBtnFollowingsClick(user: UserInfoBean)
    }

    fun setCurrentMusic(music: LocalMediaListItemBean){
        mCurrentMusic = music
        //
        mMeChannelContentNormalItemProvider.setCurrentMusic(music)
        mMeChannelContentHintItemProvider.setCurrentMusic(music)
        notifyDataSetChanged()
    }

    fun setCurrentPlayState(state: Int){
        mCurrentPlayState = state
        //
        mMeChannelContentNormalItemProvider.setCurrentPlayState(state)
        mMeChannelContentHintItemProvider.setCurrentPlayState(state)
        notifyDataSetChanged()
    }
}